#include <iostream>
#include<cstring>  //for strlen(),strcpy()
using namespace std;

struct stringy{
	char * str;     //points to a string;
	int ct;          //length of string (not counting '\0')
};

//prototypes
void set(stringy &s , const char a[]);
void show(const stringy &s , int i=1 );
void show(const char a[] , int i = 1);    

int main()
{
	stringy beany;
	char testing[] = "Reality isn't what it used to be.";

	set(beany, testing);  //first argument is a reference.
	//allocates space to hold copy of testing,
	//sets str member of beany to point to the
	//new block,copies testing to new block,
	//and sets ct member of beany
	show(beany);  //prints member string once
	show(beany, 2);//prints member string twice

	testing[0] = 'D';
	testing[1] = 'u';
	show(testing);//prints testing string once
	show(testing, 3);//prints testing string thrice

	show("Done!");

	system("pause");
	return 0;

}

void set(stringy &s, const char a[])
{
	int i = 0;
	s.ct = 0;
	while (a[i++] != '\0')
		s.ct++;
	s.str = new char[s.ct+1];
	//strcpy(s.str, a);
	while (--i)
		s.str[i] = a[i];
	s.str[0] = a[0];
	s.str[s.ct] = '\0';
}

void show(const stringy &s, int i )
{
	while (i--)
		cout << s.str << endl;
}
void show(const char a[], int i )
{
	while (i--)
		cout << a << endl;
}